package com.seeyon.apps.cxgd.service.tc;

import com.seeyon.apps.cxgd.entity.ResountEntity;
import com.seeyon.apps.cxgd.kit.LogKit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.seeyon.cap4.form.bean.FormBean;
import com.seeyon.cap4.form.bean.FormDataMasterBean;
import com.seeyon.cap4.form.bean.FormTableBean;
import com.seeyon.cap4.form.modules.engin.base.formData.CAP4FormDataManager;
import com.seeyon.cap4.form.service.CAP4FormManager;
import com.seeyon.ctp.common.AppContext;
import com.seeyon.ctp.common.exceptions.BusinessException;
import com.seeyon.ctp.common.po.ctpenumnew.CtpEnumItem;
import com.seeyon.ctp.organization.bo.V3xOrgEntity;
import com.seeyon.ctp.organization.bo.V3xOrgMember;
import com.seeyon.ctp.organization.manager.OrgManager;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 回推用车Service
 */
public class YCOrderService {
    private static Log log = LogFactory.getLog(YCOrderService.class);
    private CAP4FormManager cap4FormManager = (CAP4FormManager) AppContext.getBean("cap4FormManager");
    private CAP4FormDataManager cap4FormDataManager = (CAP4FormDataManager)AppContext.getBean("cap4FormDataManager");

    private OrgManager orgManager = (OrgManager)AppContext.getBean("orgManager");

    private final static String YC_NUMBER = "YC_DT001";




    /**
     * 回写用车表单数据
     * @param notifyData     推送主体
     * @param subNotifyType  推送子类型
     * @return
     */
    public ResountEntity ycOrder(String notifyData, String subNotifyType) throws Exception {
        log.info("推送用车订单数据："+notifyData);
        LogKit.addLog("同程回退订单-用车", "同程回退订单-用车", notifyData, "subNotifyType状态："+subNotifyType);
        return new ResountEntity(true,"100","");
    }


    /**
     * 切换订单子类型
     * 1-占座 2-出票 3-退票 4-邮寄 5-占座出票合并 6-订单过期 7-支付 8-购保 9-退保 10-抢票出票 11-抢票过期 12-抢票占座 13-取消订单 14-停运 15-H5出票推送
     * @return
     */
    private String getSubNotifyType(String subNotifyType){
        if(subNotifyType.equals("1")){
            subNotifyType = "占座";
        }else if(subNotifyType.equals("2")){
            subNotifyType = "出票";
        }else if(subNotifyType.equals("3")){
            subNotifyType = "退票";
        }else if(subNotifyType.equals("4")){
            subNotifyType = "邮寄";
        }else if(subNotifyType.equals("5")){
            subNotifyType = "占座出票合并";
        }else if(subNotifyType.equals("6")){
            subNotifyType = "订单过期";
        }else if(subNotifyType.equals("7")){
            subNotifyType = "支付";
        }else if(subNotifyType.equals("8")){
            subNotifyType = "购保";
        }else if(subNotifyType.equals("9")){
            subNotifyType = "退保";
        }else if(subNotifyType.equals("10")){
            subNotifyType = "抢票出票";
        }else if(subNotifyType.equals("11")){
            subNotifyType = "抢票过期";
        }else if(subNotifyType.equals("12")){
            subNotifyType = "抢票占座";
        }else if(subNotifyType.equals("13")){
            subNotifyType = "取消订单";
        }else if(subNotifyType.equals("14")){
            subNotifyType = "停运";
        }else if(subNotifyType.equals("15")){
            subNotifyType = "H5出票推送";
        }
        return subNotifyType;
    }



    /**
     * 给主表
     * @param masterId
     * @param formBean
     * @param filedName
     * @param fieldValue
     * @throws BusinessException
     * @throws SQLException
     */
    private void updateWuxiao(Long masterId,FormBean formBean,String filedName,String fieldValue) throws BusinessException, SQLException {
        FormDataMasterBean dataMasterBean = cap4FormManager.findDataById(masterId, formBean, null);
        dataMasterBean.addFieldValue(filedName,fieldValue);
        cap4FormDataManager.insertOrUpdateMasterData(dataMasterBean);
    }



    //订单类型转换
    private String getOrderStatus(int status){
        String typeString = "";
        switch (status){
            case 31:
                typeString = "用车结束（正常用车结束）";
                break;
            case 33:
                typeString = "已完成（收罚金取消用车订单）";
                break;
        }
        return typeString;
    }
}
